﻿Module Module1
    Const iFiles As Integer = 7
    Sub InstallFile(ByRef [byte]() As Byte, ByVal path As String)
        Static n As Integer = 0

        n += 1

        Console.WriteLine("Writing {0} ( {1}/{2} - {3}% )", path, n, iFiles, CInt(100 * n / iFiles))
        Try
            Dim r As New IO.FileStream(path, IO.FileMode.Create, IO.FileAccess.Write, IO.FileShare.None)
            r.Write([byte], 0, [byte].Length)
            r.Close()
        Catch ex As Exception
            Console.ForegroundColor = ConsoleColor.Red
            Console.WriteLine(ex.Message)
            Console.ResetColor()
        End Try
    End Sub
    Sub Main()
        Console.WriteLine("Extracting executable and core files")

        InstallFile(My.Resources.Capstone_Daycare_Client, "Daycare_Client.exe")
        InstallFile(My.Resources.Interop_WIA, "Interop.WIA.dll")
        InstallFile(My.Resources.Interop_WIALib, "Interop.WIALib.dll")
        InstallFile(My.Resources.WIAVIDEOLib, "WIAVIDEOLib.dll")
        InstallFile(My.Resources.wiaaut, "wiaaut.dll")
        InstallFile(My.Resources.ittmanual, "manual.doc")
        InstallFile(My.Resources.Child_Care_Manual, "manual.pdf")

        If Not My.User.IsInRole(ApplicationServices.BuiltInRole.Administrator) Then
            Console.WriteLine("If you are not an administrator - registration of wiaaut.dll may fail.")
        End If

        Console.WriteLine("Finished installing files")
        Console.WriteLine("Registering wiaaut.dll - the program CANNOT function without it")

        Shell(My.Resources.registrar, AppWinStyle.Hide, True)

        Console.WriteLine("Finished attempt to register wiaaut.dll")

        Console.WriteLine("Finished extracting program")
        Console.WriteLine("Press any key to continue...")

        Console.ReadKey()
    End Sub
End Module
